package com.vcg.neo4j.demo.rxjava;

import org.springframework.cloud.netflix.rx.RxResponse;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import rx.Observable;
import rx.Single;

import static javafx.scene.input.KeyCode.R;
import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8;

/**
 * Created by wuyu on 2016/7/31.
 */
@RestController
@RequestMapping(value = "/ob")
public class ObservableController {

    @RequestMapping(value = "/single",method = RequestMethod.GET)
    public Single<String> single(){
        return Single.just("single");
    }

    @RequestMapping(method = RequestMethod.GET, value = "/sse")
    public SseEmitter sse() {
        return RxResponse.sse(Observable.just("single value"));
    }

    @RequestMapping(method = RequestMethod.GET, value = "/messages")
   public SseEmitter messages() {
        return RxResponse.sse(Observable.just("message 1", "message 2", "message 3"));
    }


}
